package com.neusoft.mid.msf.common.msg;

import lombok.Data;
import org.jsoup.select.Evaluator;

import java.util.List;

/**
 * @program: pangu
 * @description: 分页查询返回对象
 * @author: fengjd
 * @create: 2022-07-25 10:36
 **/
@Data
public class TableResultResponse<T> extends BaseResponse {
    private  TableData<T> data ;

    public TableResultResponse(long total, List<T> rows ) {
        this.data = new TableData(total, rows);
    }

    public TableResultResponse() {
        this.data = new TableData<T>();
    }

    public TableResultResponse<T> total(int total){
        this.data.setTotal(total);
        return this;
    }

    public TableResultResponse<T> total(List<T> rows) {
        this.data.setRows(rows);
        this.data.setTotal(rows.size());
        return this;
    }

    public T firstRecord() {
        if (data.getRows()!=null && !data.getRows().isEmpty()){
            return data.getRows().get(0);
        }
        return null;
    }

    public TableResultResponse(TableData<T> data) {
        this.data = data;
    }

    @Data
    public static class TableData<T> {
        private long total;
        private List<T> rows;

        public TableData(long total, List<T> rows) {
            this.total = total;
            this.rows = rows;
        }

        public TableData() {
        }
    }
}
